/**
 * INSPINIA - Responsive Admin Theme
 *
 * Inspinia theme use AngularUI Router to manage routing and views
 * Each view are defined as state.
 * Initial there are written state for all view in theme.
 *
 */
function config($stateProvider, $urlRouterProvider, $ocLazyLoadProvider, IdleProvider, KeepaliveProvider, $httpProvider) {
    $httpProvider.interceptors.push('authInterceptor');

    // Configure Idle settings
    IdleProvider.idle(5); // in seconds
    IdleProvider.timeout(120); // in seconds

    $urlRouterProvider.otherwise('/base_view/home/home_page');

    $ocLazyLoadProvider.config({
        // Set to true if you want to see what and when is dynamically loaded
        debug: false
    });

    $stateProvider
        .state('base_view', {
            abstract: true,
            url: '/base_view',
            templateUrl: 'views/common/base_view',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            serie: true,
                            name: 'toaster',
                            files: ['js/plugins/angular-toaster/toaster.min.js', 'css/plugins/angular-toaster/toaster.min.css']
                        }
                    ]);
                }
            }
        })
        .state('base_view.home', {
            abstract: true,
            url: '/home',
            templateUrl: 'views/common/content'
        })
        .state('base_view.home.home_page', {
            url: '/home_page',
            templateUrl: 'views/home_page',
            data: {pageTitle: 'HomePage'},
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            serie: true,
                            name: 'chart.js',
                            files: ['js/plugins/chartJs/Chart.min.js', 'js/plugins/angular-chart/angular-chart.min.js']
                        }
                    ]);
                }
            }
        })
        .state('base_view.trans', {
            abstract: true,
            url: '/trans',
            templateUrl: 'views/common/content'
        })
        .state('base_view.trans.trans_info', {
            url: '/trans_info',
            templateUrl: 'views/trans/trans_info'
        })
        .state('base_view.trans.trans_change', {
            url: '/trans_change',
            templateUrl: 'views/trans/trans_change',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angularFileUpload',
                            files: ['js/plugins/angular-file-upload/angular-file-upload.min.js']
                        },
                        {
                            files: ['css/plugins/jasny-bootstrap/jasny-bootstrap.min.css']
                        }/*, {
                            serie: true,
                            name: 'angular-ladda',
                            files: ['js/plugins/ladda/spin.min.js', 'js/plugins/ladda/ladda.min.js', 'css/plugins/ladda/ladda-themeless.min.css', 'js/plugins/ladda/angular-ladda.min.js']
                        }*/
                    ]);
                }
            }
        })
        .state('base_view.trans.trans_bond_info', {
            url: '/trans_bond_info',
            templateUrl: 'views/trans/trans_bond_info'
        })
        .state('base_view.risk_monitor', {
            abstract: true,
            url: '/risk_monitor',
            templateUrl: 'views/common/content'
        })
        .state('base_view.risk_monitor.refused_statistics', {
            url: '/refused_statistics',
            templateUrl: 'views/risk/risk_refused_statistics',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        }
                    ]);
                }
            }
        })
        .state('base_view.bank_area', {
            abstract: true,
            url: '/bank_area',
            templateUrl: 'views/common/content'
        })
        .state('base_view.bank_area.acquirer', {
            url: '/acquirer',
            templateUrl: 'views/bank_area/acquirer'
        })
        .state('base_view.bank_area.acquirer_account', {
            url: '/acquirer_account',
            templateUrl: 'views/bank_area/acquirer_account'
        })
        .state('base_view.bank_area.acquirer_bank', {
            url: '/acquirer_bank',
            templateUrl: 'views/bank_area/acquirer_bank'
        })
        .state('base_view.user', {
            abstract: true,
            url: '/user',
            templateUrl: 'views/common/content'
        })
        .state('base_view.user.user_mgmt', {
            url: '/user_mgmt',
            templateUrl: 'views/user/user_mgmt'
        })
        .state('base_view.user.role_mgmt', {
            url: '/role_mgmt',
            templateUrl: 'views/user/role_mgmt'
        })
        .state('base_view.system_settings', {

        	abstract: true,
            url: '/system_settings',
            templateUrl: 'views/common/content'

        })
        .state('base_view.system_settings.constantlist', {

        	url: '/constantlist',
            templateUrl: 'views/constant/constantlist',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']

                        }
                    ]);
                }
            }
        })
        .state('base_view.system_settings.system_log', {
            url: '/system_log',
            templateUrl: '/views/system_settings/system_log'
        })
        // 风控模块
        .state('base_view.risk',{
            abstract: true,
            url: '/risk',
            templateUrl: 'views/common/content'
        })
        // 风控限次管理
        .state('base_view.risk.indefinitely',{
            url: '/indefinitely',
            templateUrl: 'views/risk/risk_indefinitely',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                     return $ocLazyLoad.load([
                         {
                             name: 'angucomplete-alt',
                             files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                         },
                         {
                             name: 'jquery.utils',
                             files: ['js/jquery/jquery.utils.js']
                         },
                         {
                             name: 'ajax',
                             files: ['js/ajax/ajax.js']
                         }
                    ]);
                }
            }
        })
        // 风控限额管理
        .state('base_view.risk.limit',{
            url: '/limit',
            templateUrl: 'views/risk/risk_limit',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        },
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']
                        }
                    ]);
                }
            }
        })
        //风控拒绝管理
        .state('base_view.risk.refused',{
            url: '/refused',
            templateUrl: 'views/risk/risk_refused',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        },
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']
                        }
                    ]);
                }
            }
        })
        //外置风控管理
        .state('base_view.risk.outer',{
            url: '/outer',
            templateUrl: 'views/risk/risk_outer',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        },
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']
                        }
                    ]);
                }
            }
        })
        // 黑卡库管理
        .state('base_view.risk.blackcard',{
            url: '/blackcard',
            templateUrl: 'views/risk/risk_blackcard',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        },
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']
                        }
                    ]);
                }
            }
        })
        // 商务卡管理
        .state('base_view.risk.business',{
             url: '/business',
             templateUrl: 'views/risk/risk_business',
             resolve: {
                 loadPlugin: function ($ocLazyLoad) {
                     return $ocLazyLoad.load([
                         {
                             name: 'angucomplete-alt',
                             files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                         },
                         {
                             name: 'jquery.utils',
                             files: ['js/jquery/jquery.utils.js']
                         },
                         {
                             name: 'ajax',
                             files: ['js/ajax/ajax.js']
                         }
                     ]);
                 }
             }
        })
        //发卡行管理
        .state('base_view.risk.issuers',{
             url: '/issuers',
             templateUrl: 'views/risk/risk_issuers',
             resolve: {
                 loadPlugin: function ($ocLazyLoad) {
                     return $ocLazyLoad.load([
                         {
                             name: 'angucomplete-alt',
                             files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                         },
                         {
                             name: 'jquery.utils',
                             files: ['js/jquery/jquery.utils.js']
                         },
                         {
                             name: 'ajax',
                             files: ['js/ajax/ajax.js']
                         }
                     ]);
                 }
             }
        })

        //运营模块
        .state('base_view.operation',{
            abstract: true,
            url: '/operation',
            templateUrl: 'views/common/content'
        })
        //异常单管理
        .state('base_view.operation.abnormal',{
            url: '/abnormal',
            templateUrl: 'views/operation/operation_abnormal',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        },
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']
                        }
                    ]);
                }
            }
        })
        //提现审核管理
        .state('base_view.operation.withdrawal',{
            url: '/withdrawal/:type',
            templateUrl: 'views/operation/operation_withdrawal',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        },
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']
                        }
                    ]);
                }
            }
        })

        .state('base_view.business', {

        	abstract: true,
            url: '/business',
            templateUrl: 'views/common/content'

        })
        .state('base_view.business.merchant_mgmt', {
            url: '/merchant_mgmt',
            templateUrl: 'views/business/merchant_mgmt'
        })
        .state('base_view.business.merchant_info', {
            url: '/merchant_info',
            templateUrl: 'views/business/merchant_info',
            params: {
                merchant: null,
                goType: null,
                merchantCategory: null,
                businessType: null
            },
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angularFileUpload',
                            files: ['js/plugins/angular-file-upload/angular-file-upload.min.js']
                        },
                        {
                            files: [
                                'css/plugins/Gallery-master/blueimp-gallery.min.css',
                                'js/plugins/Gallery-master/jquery.blueimp-gallery.min.js']
                        }
                    ]);
                }
            }
        })
        .state('base_view.business.merchant_setting', {
            url: '/merchant_setting',
            templateUrl: 'views/business/merchant_setting',
            params: {
                merchant: null,
                goType: null
            }
        })
        .state('base_view.business.merchant_pay', {
            url: '/merchant_pay',
            templateUrl: 'views/business/merchant_pay',
            params: {
                merchant: null,
                goType: null
            }
        })
        .state('base_view.business.merchant_user', {
            url: '/merchant_user',
            templateUrl: 'views/business/merchant_user',
            params: {
                merchant: null
            }
        })
        .state('base_view.business.merchant_web_site', {
            url: '/merchant_web_site',
            templateUrl: 'views/business/merchant_web_site'
        })
        .state('base_view.business.merchant_web_site_rate', {
            url: '/merchant_web_site_rate',
            templateUrl: 'views/business/merchant_web_site_rate',
            params: {
                webSiteInfo: null
            }
        })
        .state('base_view.business.merchant_website_pro_type', {
            url: '/industry_mgmt',
            templateUrl: 'views/business/merchant_website_pro_type'
        })
        .state('base_view.business.quick_test', {
            url: '/quick_test',
            templateUrl: 'views/business/quick_test'
        })
        .state('base_view.business.businessMoney', {

        	url: '/businessMoney',
            templateUrl: 'views/business/businessMoney',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        },
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']
                        }
                    ]);
                }
            }

        })
        .state('base_view.businessdetails', {

        	abstract: true,
            url: '/business',
            templateUrl: 'views/common/content'

        })
        .state('base_view.business.businessMoneydetails', {

        	params : {//跳转设置参数merId
                 'merId':null
                },
        	url: '/businessMoneyDetails?:merId',
            templateUrl: 'views/business/businessMoneyDetails',
            	resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']
                        }
                    ]);
                }
            }


        })
        .state('base_view.businessRecon', {

        	abstract: true,
            url: '/businessReconReport',
            templateUrl: 'views/common/content'

        })
        .state('base_view.businessRecon.report', {

        	url: '/report',
            templateUrl: 'views/businessRecon/businessReconReport',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        },
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']
                        }
                    ]);
                }
            }
            	
        })
        .state('base_view.financialSection', {

        	abstract: true,
            url: '/financialSection',
            templateUrl: 'views/common/content'

        })
        .state('base_view.financialSection.refundlist', {

        	url: '/refundlist',
            templateUrl: 'views/financialSection/refundlist',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        }
                    ]);
                }
            }

        })
        .state('base_view.financialSection.protestlist', {

        	url: '/protestlist',
            templateUrl: 'views/financialSection/protestlist',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        }
                    ]);
                }
            }

        })
        .state('base_view.financialSection.transferlist', {

        	url: '/transferlist',
            templateUrl: 'views/financialSection/transferlist',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        },
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']
                        }
                    ]);
                }
            }	
            	
        })
        .state('base_view.financialSection.withdrawalProcessing', {

            url: '/withdrawal/:type',
            templateUrl: 'views/operation/operation_withdrawal',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        },
                        {
                            name: 'jquery.PrintArea',
                            files: ['js/jquery/jquery.PrintArea.js']
                        }
                    ]);
                }
            }

        })
        .state('base_view.financialSection.transferMoney', {
            url: '/withdrawal/:type',
            templateUrl: 'views/operation/operation_withdrawal',
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        }
                    ]);
                }
            }

        })
        .state('base_view.exchangeRateSection', {
           
        	abstract: true,
            url: '/exchangeRateSection',
            templateUrl: 'views/common/content'
            	
        })
        .state('base_view.exchangeRateSection.tradeRateList', {
        	
        	url: '/tradeRateList',
            templateUrl: 'views/exchangeRateSection/tradeRateList',	
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        },
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']
                        }
                    ]);
                }
            }	
            	
        })
        .state('base_view.exchangeRateSection.transferRateList', {
        	
        	url: '/transferRateList',
            templateUrl: 'views/exchangeRateSection/transferRateList',	
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']
                        }
                    ]);
                }
            }
            	
        })
        .state('base_view.exchangeRateSection.channelRateList', {
        	
        	url: '/channelRateList',
            templateUrl: 'views/exchangeRateSection/channelRateList',	
            resolve: {
                loadPlugin: function ($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        {
                            name: 'jquery.utils',
                            files: ['js/jquery/jquery.utils.js']
                        },
                        {
                            name: 'ajax',
                            files: ['js/ajax/ajax.js']
                        },
                        {
                            name: 'angucomplete-alt',
                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
                        }
                    ]);
                }
            }
            	
        })
        .state('base_view.riskAnalysis', {

        	abstract: true,
            url: '/riskAnalysis',
            templateUrl: 'views/common/content'

        })
        .state('base_view.riskAnalysis.orderTrack', {

        	url: '/orderTrack',
            templateUrl: 'views/riskAnalysis/orderTracklist',	
            resolve: {
	                loadPlugin: function ($ocLazyLoad) {
	                    return $ocLazyLoad.load([
	                        {
	                            name: 'angucomplete-alt',
	                            files: ['js/plugins/angucomplete-alt/angucomplete-alt.js', 'css/plugins/angucomplete-alt/angucomplete-alt.css']
	                        }
	                    ]);
	                }
                }
            	
        });
}

function authInterceptor($rootScope, $q, $window) {
    return {
        request: function (config) {
            config.headers = config.headers || {};
            if ($window.sessionStorage.token) {
                config.headers.Authorization = 'Bearer ' + $window.sessionStorage.token;
            }
            return config;
        },
        response: function (response) {
            if (response.status === 401) {
                location.reload();
            }
            return response || $q.when(response);
        }
    };
}

angular
    .module('inspinia')
    .factory('authInterceptor', authInterceptor)
    .config(config)
    .run(function ($rootScope, $state) {
        $rootScope.$state = $state;
    });
